package com.frkj.yuan.activity;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.provider.Settings;
import android.view.View;
import android.widget.TextView;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.frkj.yuan.R;
import com.frkj.yuan.base.BaseActivity;
import com.frkj.yuan.dialog.RoundKefuDialog;
import com.frkj.yuan.utils.FullScreenUtils;

import butterknife.BindView;
import butterknife.OnClick;
import cn.ycbjie.ycstatusbarlib.bar.YCAppBar;

/**
 * 信息说明: 招募陪诊员
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/4 16 ：16
 * 项目名称：yuanban
 */
public class RecruitAccompanyingMemberActivity extends BaseActivity {
    @BindView(R.id.base_title)
    TextView mTitleMsg;
    @Override
    public int getLayoutId() {
        return R.layout.activity_recruit_view;
    }
    @Override
    public void initLayoutView() {
        mTitleMsg.setText("陪诊员招募");
        FullScreenUtils.getInstance().fullScreen(RecruitAccompanyingMemberActivity.this, true);
    }

    @OnClick({R.id.base_back, R.id.shenqing_msg, R.id.kefu_msg})
    public void OnClick(View view) {
        switch (view.getId()) {
            case R.id.base_back:
                finishWitchAnimation();
                break;
            case R.id.shenqing_msg:
                openActivityWitchAnimation(ZhaomuPeiZhenYuanActivity.class);
                break;
            case R.id.kefu_msg:
                RoundKefuDialog dialog = new RoundKefuDialog(RecruitAccompanyingMemberActivity.this);
                dialog.show();
                TextView mobile = dialog.findViewById(R.id.mobile_number);
                mobile.setText( "0931-8797777");
                dialog.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialog.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        // 检查是否获得了权限
                        if (ContextCompat.checkSelfPermission(RecruitAccompanyingMemberActivity.this,
                                Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
                            // 若没有获得授权，申请授权
                            if (ActivityCompat.shouldShowRequestPermissionRationale(RecruitAccompanyingMemberActivity.this,
                                    Manifest.permission.CALL_PHONE)) {
                                // 如果app之前请求过该权限,被用户拒绝, 这个方法就会返回true.
                                //  如果用户之前拒绝权限的时候勾选了对话框中”Don’t ask again”的选项,那么这个方法会返回false.
                                // 如果设备策略禁止应用拥有这条权限, 这个方法也返回false.
                                // 弹窗需要解释为何需要该权限，再次请求授权
                                // 帮跳转到该应用的设置界面，让用户手动授权
                                Intent call = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                                Uri uri = Uri.fromParts("package", RecruitAccompanyingMemberActivity.this.getPackageName(), null);
                                call.setData(uri);
                                startActivity(call);
                            } else {
                                // 不需要解释为何需要该权限，直接请求授权
                                ActivityCompat.requestPermissions(RecruitAccompanyingMemberActivity.this,
                                        new String[]{Manifest.permission.CALL_PHONE},
                                        0);
                            }
                        } else {
                            // 已经获得授权，可以打电话
                            // 通过intent跳转到拨打电话的界面
                            Intent intent1 = new Intent();
                            intent1.setAction(Intent.ACTION_CALL);
                            Uri phoneNum = Uri.parse("tel:" + "0931-8797777");
                            intent1.setData(phoneNum);
                            startActivity(intent1);
                        }
                        dialog.dismiss();
                    }
                });
                break;
        }
    }
}
